<template>
  <!-- 首页推荐 -->
  <div id="homeRecommend" v-if="articles.length > 0">
    <div class="adv-content">
      <p>Hello World!</p>
    </div>
    <div class="recommend-item-box">
      <div class="recommend-item" v-for="item in articles" :key="item.id">
        <div class="recommend-item-left">
          <el-image class="img" :src="item.cover"></el-image>
        </div>

        <div class="recommend-item-right">
          <div class="title-box">
            <el-link :underline="false" class="title" @click="showDetail(item.id)">
              {{ item.title }}
            </el-link>
          </div>
          <div class="content">
            {{ item.content }}
          </div>

          <div class="params">
            <i class="el-icon-menu">&nbsp;{{ item.categoryName }}</i>&nbsp;&nbsp;&nbsp;
            <i class="el-icon-user-solid">&nbsp;{{ item.author }}</i>&nbsp;&nbsp;&nbsp;
            <i class="el-icon-time">&nbsp;{{ item.createTime | formatTimer }}</i>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
    articleQueryList
} from '@/api/article'

export default {
    name: 'my-homeRecommend',
    data () {
        return {
            articles: []
        }
    },
    filters: {
        formatTimer: function (value) {
            let date = new Date(value)
            let year = date.getFullYear()

            let month = date.getMonth() + 1
            month = month < 10 ? '0' + month : month

            let day = date.getDate()
            day = day < 10 ? '0' + day : day

            let hour = date.getHours()
            hour = hour < 10 ? '0' + hour : hour

            let minute = date.getMinutes()
            minute = minute < 10 ? '0' + minute : minute

            let second = date.getSeconds()
            second = second < 10 ? '0' + second : second

            console.log(year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second)
            return year + '-' + month + '-' + day
        }
    },
    methods: {
        showDetail (articleId) {
            this.$router.push({
                path: 'articleDetail',
                query: {
                    'articleId': articleId
                }
            })
        }
    },
    mounted () {
        articleQueryList({
            isRecommend: true,
            limit: 20
        }).then((response) => {
            if (response && response.code === 200) {
                this.articles = response.data
            }
        })
    },
    created () {
    }
}
</script>

<style scoped>
/* 最外层div id选择器 */
#homeRecommend {
  width: 100%;
  height: auto;
  margin-top: 0px;
  margin-bottom: 10px;
}

/* 横条 */
.adv-content {
  color: white;
  width: auto;
  height: 80px;
  line-height: 80px;
  text-align: center;
  font-size: 25px;
  margin: 0px;
  /* background-image: url("../assets/images/bg_rainbow.png") !important; */
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-color: #fff;
  margin: 0px 0px 0px 0px;
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(232, 169, 200)), to(rgb(10, 156, 137)));
}

.recommend-item-box {
  width: 100%;
  height: auto;
  margin-top: 5px;
}

.recommend-item {
  width: auto;
  height: 150px;
  margin: 0px 0px 5px 0px;
  padding: 0px 0px 0px 0px;
  border: 1px solid #999;
  display: flex;
  flex-direction: row;
  background-color: #fff;
}

.recommend-item-left {
  width: 30%;
  height: auto;
}

.img {
  width: 100%;
  height: 150px;
  display: block;
  margin: 0px 0px 0px 0px;
}

.recommend-item-right {
  width: 70%;
  height: auto;
  padding: 5px;
}

/* 标题内容 */
.title-box {
  width: auto;
  height: 30px;
  line-height: 30px;
}

.title {
  color: #000;
  font-size: 16px;
  font-weight: 600;
}

.content {
  font-size: 12.8px;
  font-weight: 400;
  margin-top: 5px;
  height: 81px;
  line-height: 27px;
  color: dimgray;
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.params {
  color: rgb(46, 158, 237);
  height: 30px;
  line-height: 30px;
  text-align: left;
}
</style>
